package org.example.struct.array;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author liyishan
 * @date 2023/8/10 10:54
 * @apiNote
 */

public class Test00989AddToArrayForm {

    public static void main(String[] args) {
        int[] num = new int[]{1,2,0,7};
        List<Integer> res= test(num,9993);
        System.out.println(JSON.toJSON(res));
    }

    public static List<Integer> test(int[] num, int k) {
        List<Integer> res = new ArrayList<Integer>();
        int n = num.length;
        for (int i = n - 1; i >= 0; --i) {
            int sum = num[i] + k % 10;
            k /= 10;
            if (sum >= 10) {
                k++;
                sum -= 10;
            }
            res.add(sum);
        }
        for (; k > 0; k /= 10) {
            res.add(k % 10);
        }
        Collections.reverse(res);
        return res;
    }
}
